home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / include / user / RCS / spriteTime.h,v < prev    next >
Encoding:
Text File  |  1992-07-17  |  5.7 KB  |  250 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.3 srv027:1.3 srv026:1.3 srv024:1.3 srv021:1.3 srv019:1.3 srv018:1.3 srv016:1.3 srv014:1.3 srv010:1.3 srv008:1.3 srv007:1.3 srv006:1.3 srv005:1.3 srv004:1.3 srv003:1.3 srv002:1.3 srv001:1.2;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     92.04.23.23.56.18;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     92.03.12.20.45.28;  author kupfer;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     92.03.04.16.50.21;  author kupfer;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @Add Time_ToMs and Time_Average.
  32. @
  33. text
  34. @/*
  35.  * time.h --
  36.  *
  37.  *     External definitions for the time utility routines.
  38.  *
  39.  * Copyright 1986, 1988 Regents of the University of California
  40.  * Permission to use, copy, modify, and distribute this
  41.  * software and its documentation for any purpose and without
  42.  * fee is hereby granted, provided that the above copyright
  43.  * notice appear in all copies.  The University of California
  44.  * makes no representations about the suitability of this
  45.  * software for any purpose.  It is provided "as is" without
  46.  * express or implied warranty.
  47.  *
  48.  * rcsid: $Header: /user5/kupfer/spriteserver/include/user/RCS/spriteTime.h,v 1.2 92/03/12 20:45:28 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)
  49.  */
  50.  
  51. #ifndef _SPRITETIME
  52. #define _SPRITETIME
  53.  
  54. #ifndef _SPRITE
  55. #include <sprite.h>
  56. #endif
  57.  
  58. /* DATA STRUCTURES */
  59.  
  60. /*
  61.  *  Definition of a time value.
  62.  *  Warning: if you change the definition of Time, be sure to update 
  63.  *  spriteTypes.defs.
  64.  */
  65.  
  66. typedef struct {
  67.     int    seconds;
  68.     int    microseconds;
  69. } Time;
  70.  
  71. typedef struct {
  72.     int year;
  73.     int month;
  74.     int dayOfYear;
  75.     int dayOfMonth;
  76.     int dayOfWeek;
  77.     int    hours;
  78.     int    minutes;
  79.     int    seconds;
  80.     int localOffset;
  81.     Boolean dst;
  82. } Time_Parts;
  83.  
  84. /* CONSTANTS */
  85.  
  86. /*
  87.  *  The number of microseconds in one second and one millisecond.
  88.  */
  89.  
  90. #define ONE_SECOND        1000000
  91. #define TENTH_SECOND        100000
  92. #define HUNDREDTH_SECOND    10000
  93. #define ONE_MILLISECOND        1000
  94.  
  95. /*
  96.  *  Length of buffers required by the Time conversion routines.
  97.  */
  98.  
  99. #define TIME_CVT_BUF_SIZE 30
  100.  
  101. /*
  102.  *  Frequently used time values.
  103.  */
  104.  
  105. extern Time time_ZeroSeconds;
  106. extern Time time_OneMicrosecond;
  107. extern Time time_OneMillisecond;
  108. extern Time time_TenMilliseconds;
  109. extern Time time_HundredMilliseconds;
  110. extern Time time_HalfSecond;
  111. extern Time time_OneSecond;
  112. extern Time time_TwoSeconds;
  113. extern Time time_TenSeconds;
  114. extern Time time_OneMinute;
  115. extern Time time_OneHour;
  116. extern Time time_OneDay;
  117. extern Time time_OneYear;
  118. extern Time time_OneLeapYear;
  119.  
  120.  
  121. /* PROCEDURES */
  122.  
  123. extern void    Time_Add _ARGS_((Time time1, Time time2, Time *resultPtr));
  124. extern void    Time_Subtract _ARGS_((Time time1, Time time2,
  125.                       Time *resultPtr));
  126. extern void    Time_Multiply _ARGS_((Time time, int factor, Time *resultPtr));
  127. extern void    Time_Divide _ARGS_((Time time, int factor, Time *resultPtr));
  128. extern void    Time_Normalize _ARGS_((Time *timePtr));
  129. extern void    Time_ToAscii _ARGS_((int time, Boolean relativeTime,
  130.                      char *bufferPtr));
  131. extern void    Time_ToParts _ARGS_((int time, Boolean relativeTime,
  132.                      Time_Parts *partsPtr));
  133.  
  134.  
  135. /*
  136.  *----------------------------------------------------------------------
  137.  *
  138.  * Time Comparisons --
  139.  *
  140.  *    Time_LT:    time1  <   time2
  141.  *    Time_LE:    time1  <=  time2
  142.  *    Time_EQ:    time1  ==  time2
  143.  *    Time_GE:    time1  >=  time2
  144.  *    Time_GT:    time1  >   time2
  145.  *
  146.  * Results:
  147.  *     TRUE    - the relation holds for the 2 values.
  148.  *     FALSE    - the relation does not hold.
  149.  *
  150.  * Side effects:
  151.  *     None.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155.  
  156. #define Time_LT(time1, time2) \
  157.         (((time1).seconds     <  (time2).seconds) ||  \
  158.          (((time1).seconds     == (time2).seconds) &&  \
  159.           ((time1).microseconds <  (time2).microseconds)))
  160.  
  161. #define Time_LE(time1, time2) \
  162.         (((time1).seconds     <  (time2).seconds) ||  \
  163.          (((time1).seconds     == (time2).seconds) &&  \
  164.           ((time1).microseconds <= (time2).microseconds)))
  165.  
  166. #define Time_EQ(time1, time2) \
  167.         (((time1).seconds     == (time2).seconds) &&  \
  168.          ((time1).microseconds == (time2).microseconds))
  169.  
  170. #define Time_GE(time1, time2) \
  171.         (((time1).seconds     >  (time2).seconds) ||  \
  172.          (((time1).seconds     == (time2).seconds) &&  \
  173.           ((time1).microseconds >= (time2).microseconds)))
  174.  
  175. #define Time_GT(time1, time2) \
  176.         (((time1).seconds     >  (time2).seconds) ||  \
  177.          (((time1).seconds     == (time2).seconds) &&  \
  178.           ((time1).microseconds >  (time2).microseconds)))
  179.  
  180.  
  181. /*
  182.  *----------------------------------------------------------------------
  183.  *
  184.  * Time_ToMs --
  185.  *
  186.  *    Convert a time value (usually a small interval) to a floating-point 
  187.  *    number of milliseconds.
  188.  *
  189.  * Results:
  190.  *    Returns a float.
  191.  *
  192.  * Side effects:
  193.  *    None.
  194.  *
  195.  *----------------------------------------------------------------------
  196.  */
  197.  
  198. #define Time_ToMs(time)    ((float)(time).seconds * 1000 + \
  199.              (float)(time).microseconds / 1000)
  200.  
  201.  
  202. /*
  203.  *----------------------------------------------------------------------
  204.  *
  205.  * Time_Average --
  206.  *
  207.  *    Return the average time from some total.
  208.  *
  209.  * Results:
  210.  *    Returns the total time divided by the given count.  Returns 0 if 
  211.  *    the count is 0.  Be sure to cast this if total is a float.
  212.  *
  213.  * Side effects:
  214.  *    None.
  215.  *
  216.  *----------------------------------------------------------------------
  217.  */
  218.  
  219. #define Time_Average(total, count) ((count) == 0 ? 0 : (total) / (count))
  220.  
  221. #endif /* _SPRITETIME */
  222. @
  223.  
  224.  
  225. 1.2
  226. log
  227. @Add warning about changing Time.
  228. @
  229. text
  230. @d15 1
  231. a15 1
  232.  * rcsid: $Header: /user5/kupfer/spriteserver/include/user/RCS/spriteTime.h,v 1.1 92/03/04 16:50:21 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)
  233. d146 41
  234. @
  235.  
  236.  
  237. 1.1
  238. log
  239. @Initial revision
  240. @
  241. text
  242. @d15 1
  243. a15 1
  244.  * rcsid: $Header: /sprite/src/lib/include/RCS/spriteTime.h,v 1.4 90/09/11 14:40:15 kupfer Exp $ SPRITE (Berkeley)
  245. d22 1
  246. a22 1
  247. #include "sprite.h"
  248. d29 2
  249. @
  250.